using System;
using System.Collections.Generic;

using Mono.Addins;

namespace Gazebo.Core
{
    public static class AddinUtilities
    {
        public static IEnumerable<T> GetExtensionObjects<T>(string path) where T : class
        {
            foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes(path, typeof(TypeExtensionNode))) {
                T obj = node.GetInstance() as T;
                
                if (obj != null) {
                    yield return obj;
                }
            }
        }
        
        public static IEnumerable<T> CreateExtensionObjects<T>(string path) where T : class
        {
            foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes(path, typeof(TypeExtensionNode))) {
                T obj = node.CreateInstance() as T;
                
                if (obj != null) {
                    yield return obj;
                }
            }
        }
    }
}
